home *** CD-ROM | disk | FTP | other *** search
- #include "project.h"
- #include <exec/types.h>
- #include "FileRequester/pcg_FileReq.h"
- #include "BuilderWindow.h"
- #include "BuilderMethods/BuilderMethods.h"
- #include "saveprompt.h"
- #include "BuilderMethods/panelio.h"
- #include <string.h>
- #include <stdio.h>
- #include "MsgWindow.h"
- #include "makeicon.h"
- #include "dumpwait.h"
-
- extern struct FileReqInfo filereq_info;
- extern BuilderWindow builderwindow;
-
- void Builder_Init( void );
- void Builder_CleanUp( void );
- void Builder_Reset( BOOL reopen );
- void EnableAllChainedWindows( BOOL );
-
- #define STRINGSIZE 129
-
- BOOL proj_modified;
- BOOL proj_done;
-
- char proj_file[STRINGSIZE];
- char proj_code[STRINGSIZE];
-
- char *proj_filename;
- char *proj_codename;
-
- char message[80];
-
- void Project_Init( void )
- {
- proj_modified = FALSE;
- proj_done = FALSE;
-
- proj_filename = NULL;
- proj_codename = NULL;
-
- proj_file[0] = '\0';
- proj_code[0] = '\0';
- }
-
-
- BOOL Project_Modified( void )
- {
- return proj_modified;
- }
-
- BOOL Project_Done( void )
- {
- return proj_done;
- }
-
-
- BOOL Prompt_Save( void )
- {
- int save_choice;
- BOOL result;
-
- if( ! Project_Modified() ) return TRUE;
-
- save_choice = do_SavePrompt();
-
- switch( save_choice )
- {
- case SP_CANCEL:
- result = FALSE;
- break;
-
- case SP_SAVE:
- result = Project_Save();
- break;
-
- case SP_DONT_SAVE:
- result = TRUE;
- break;
- }
- return result;
- }
-
- void Project_Modify( void )
- {
- proj_modified = TRUE;
- }
-
-
- void Project_Quit( void )
- {
- if( Prompt_Save() )
- proj_done = TRUE;
- }
-
-
- /*-------------------------------*/
-
-
- BOOL Project_WriteIFF( void )
- {
- FILE *file;
-
- if( file = fopen( proj_file, "w" ) )
- {
-
- /* printf( "Saving \"%s\"...\n", proj_file ); */
-
- WritePrecogForm( file, &builderwindow );
-
- fclose( file );
-
- proj_modified = FALSE;
- proj_filename = proj_file;
-
- makeIcon( proj_file );
-
- return TRUE;
- }
- else
- {
- sprintf( message, "Couldn't open file \"%s\"", proj_file );
- do_MsgWindow( message );
- return FALSE;
- }
- }
-
- BOOL Project_ReadIFF( void )
- {
- FILE *file;
- long status;
- BOOL result;
-
-
- if( ( file = fopen( proj_file, "r" ) ) != NULL )
- {
-
- /* printf("Reading \"%s\"...\n", proj_file ); */
-
- status = ReadPrecogFile( file, &builderwindow );
-
- fclose( file );
-
- proj_modified = FALSE;
- proj_filename = proj_file;
-
- result = (BOOL)( !status );
-
- if( status < 0 )
- {
- sprintf( message, "Don't understand file \"%s\".", proj_file );
- do_MsgWindow( message );
- }
- }
- else
- {
- sprintf( message, "Couldn't open file \"%s\"", proj_file );
- do_MsgWindow( message );
- result = FALSE;
- }
-
- return result;
- }
-
-
- BOOL Project_Save_As( void )
- {
- BOOL result = FALSE;
-
- EnableAllChainedWindows( FALSE );
-
-
- filereq_info.title = "Save as what file?";
- filereq_info.MustExist = FALSE;
- filereq_info.FullPathName = proj_file;
-
- if( proj_file[0] == '\0' ) /* Create a default filename. */
- {
- strcat( proj_file, PObjectName( (struct PObject *)&builderwindow ) );
- }
-
- if( pcg_FileReq( &filereq_info ) )
- {
- result = Project_WriteIFF();
- }
- else
- {
- result = FALSE;
- }
-
- EnableAllChainedWindows( TRUE );
-
- return result;
- }
-
-
- BOOL Project_Save( void )
- {
- BOOL result;
-
- if( proj_filename == NULL )
- {
- result = Project_Save_As();
- }
- else
- {
- EnableAllChainedWindows( FALSE );
- result = Project_WriteIFF();
- EnableAllChainedWindows( TRUE );
- }
-
- return result;
- }
-
-
-
- BOOL Project_New( void )
- {
- if( Project_Modified() )
- {
- /* Prompt for save */
- if( ! Prompt_Save() )
- return FALSE;
- }
-
- Builder_Reset( TRUE );
- Project_Init();
-
- return TRUE;
- }
-
-
- BOOL Project_Open( void )
- {
- BOOL result = FALSE;
-
-
- if( Project_Modified() )
- {
- /* Prompt for save */
- if( ! Prompt_Save() )
- return FALSE;
- }
-
-
- EnableAllChainedWindows( FALSE );
-
- Builder_Reset( FALSE );
- Project_Init();
-
- filereq_info.title = "Open which file?";
- filereq_info.MustExist = TRUE;
- filereq_info.FullPathName = proj_file;
-
- if( pcg_FileReq( &filereq_info ) )
- {
- result = Project_ReadIFF();
- }
- else
- {
- result = FALSE;
- }
-
- pcgOpenWindow( &builderwindow.pw );
-
- EnableAllChainedWindows( TRUE );
- return result;
- }
-
- #include "BuilderMethods/rcsio.h"
-
- void
- WriteTheCode( FILE *file, BuilderWindow *panel, int section )
- {
- GraphicObject *graphic;
- Interactor *iactor;
-
- WriteCode( (GraphicObject *)panel, panel, file, section );
-
- for( graphic = panel->pw.FirstGraphic; graphic != NULL; graphic = graphic->Next )
- {
- WriteCode( graphic, panel, file, section );
- }
-
- for( iactor = panel->eb.Next; iactor != NULL; iactor = iactor->Next )
- {
- WriteCode( (struct GraphicObject *)iactor, panel, file, section );
- }
- }
-
- BOOL Project_WriteCode( void )
- {
- RCSFILE *rcsfile;
- FILE *file;
- short i;
- BOOL result = FALSE;
-
- EnableAllChainedWindows( FALSE );
-
-
- filereq_info.title = "Write code to what file?";
- filereq_info.MustExist = FALSE;
- filereq_info.FullPathName = proj_code;
-
-
- if( proj_code[0] == '\0' ) /* Create a default filename. */
- {
- strcat( proj_code, PObjectName( (struct PObject *)&builderwindow ) );
- strcat( proj_code, ".c" );
- }
-
- if( pcg_FileReq( &filereq_info ) )
- {
-
- if( rcsfile = rcs_create( proj_code ) )
- {
- file = rcsfile->file;
-
- /* printf( "Coding \"%s\"\n", proj_code ); */
-
- for( i = 0; i < 1000; i++ )
- {
- WriteTheCode( file, &builderwindow, i );
- }
- rcs_close( rcsfile );
-
- result = TRUE;
- }
- else
- {
- printf( "Couldn't open file \"%s\"\n", proj_code );
- result = FALSE;
- }
- }
- else
- {
- result = FALSE;
- }
-
- EnableAllChainedWindows( TRUE );
-
- return result;
- }
-
- #include "AboutWindow/do_About_window.h"
-
- extern struct MsgPort *shared_port;
- extern struct Screen *screen;
-
- void Project_About( void )
- {
- EnableAllChainedWindows( FALSE );
- do_About_window( screen, shared_port );
- EnableAllChainedWindows( TRUE );
- }
-
-